package com.theBestBuy.code;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.provider.Settings.System;




public class CargaDatosWS {		
	public String checkLogin(String usuario,String password){
		String resultado ="";
		String NAMESPACE= "http://webServiceLogin";
		String URL ="http://84.123.189.232:8080/theBestBuy/services/LogicImpl?wsdl";
		String METHOD="existeUsuario";
		String SOAPACTION ="urn:existeUsuario";
	
		SoapObject request = new SoapObject(NAMESPACE, METHOD);		
		PropertyInfo nombreUsuario = new PropertyInfo();
		nombreUsuario.setName("idUsuario");
		nombreUsuario.setValue(usuario);
		nombreUsuario.setType(String.class);
		request.addProperty(nombreUsuario);


		PropertyInfo nombrePassword = new PropertyInfo();
		nombrePassword.setName("password");
		nombrePassword.setValue(password);
		nombrePassword.setType(String.class);
		request.addProperty(nombrePassword);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		//envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
		 SoapPrimitive response = null;
			try {
				androidHttpTransport.call(SOAPACTION, envelope);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (XmlPullParserException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			try {
				response = (SoapPrimitive) envelope.getResponse();
			} catch (SoapFault e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			String respuestaVacia = "existeUsuarioResponse{return=anyType{}; }"; 			
			if(response!=null){
				 String res = response.toString();
				 if(!res.equals(respuestaVacia)){
					resultado = res; 					
				}
			}

		return resultado;
	}	
	
}